package com.yj.springbootdesign.chainofresponsibility;

public abstract class AbstractHandler {
    public AbstractHandler handler;

    public AbstractHandler getHandler() {
        return handler;
    }

    public void setHandler(AbstractHandler handler) {
        this.handler = handler;
    }

    public abstract void handleRequest(String condition);


    public static void main(String[] args) {
        HandlerA handlerA = new HandlerA();
        HandlerB handlerB = new HandlerB();
        HandlerZ handlerZ = new HandlerZ();
        handlerA.setHandler(new HandlerB());
        handlerB.setHandler(new HandlerZ());
        handlerZ.handleRequest("d");
    }

}

class HandlerA extends  AbstractHandler{

    @Override
    public void handleRequest(String condition) {
        if (condition.equals("a")){
            System.out.println("处理器A处理！");
        }else {
            System.out.println("交个其他处理器处理");
            super.getHandler().handleRequest(condition);
        }
    }
}


class HandlerB extends  AbstractHandler{

    @Override
    public void handleRequest(String condition) {
        if (condition.equals("b")){
            System.out.println("处理器B处理！");
        }else {
            System.out.println("交个其他处理器处理");
            super.getHandler().handleRequest(condition);
        }
    }
}

class HandlerZ extends AbstractHandler{

    @Override
    public void handleRequest(String condition) {
        System.out.println("最终处理器处理");
    }
}
